import http from '@/api/request';

export const getOrderGoods = (orderGoods: string) => {
  return http.request({
    method: 'GET',
    url: '/app/goods/order_goods',
    params: { order_goods: orderGoods },
  });
};

export const getOrderAddress = (addressId: number) => {
  return http.request({
    method: 'GET',
    url: '/app/goods/order_address',
    params: { address_id: addressId },
  });
};

export const setOrderAddress = (addressId: number, orderNo: string) => {
  return http.request({
    method: 'POST',
    url: '/app/goods/order_address_update',
    data: { address_id: addressId, order_no: orderNo },
  });
};

export const getOrder = (page: number, limit: number, status: number, searchKey: string = '') => {
  return http.request({
    method: 'GET',
    url: '/app/goods/order_list',
    params: { page_size: limit, page: page, status: status, search_key: searchKey },
  });
};

export const getOrderDetail = (orderNo: string) => {
  return http.request({
    method: 'GET',
    url: '/app/goods/order_detail',
    params: { order_no: orderNo },
  });
};

export const createOrder = (
  addressId: number,
  orderGoods: string,
  payWay: number,
  voucher: string,
  remark: string
) => {
  return http.request({
    method: 'POST',
    url: '/app/goods/order_create',
    data: {
      address_id: addressId,
      order_goods: orderGoods,
      pay_type: payWay,
      voucher: voucher,
      remark: remark,
    },
  });
};

export const getOrderFreight = (addressId: number, orderGoods: string) => {
  return http.request({
    method: 'POST',
    url: '/app/goods/dada_deliver_fee',
    data: { address_id: addressId, order_goods: orderGoods },
  });
};

export const submitOrderVoucher = (orderNo: string, payWay: number, voucher: string) => {
  return http.request({
    method: 'POST',
    url: '/app/goods/order_voucher_submit',
    data: { order_no: orderNo, pay_type: payWay, voucher: voucher },
  });
};

export const wxpayOrder = (orderNo: string) => {
  return http.request({
    method: 'POST',
    url: '/app/goods/order_wxpay',
    data: { order_no: orderNo },
  });
};

export const cancelOrder = (orderNo: string) => {
  return http.request({
    method: 'POST',
    url: '/app/goods/order_cancel',
    data: { order_no: orderNo },
  });
};

export const signOrder = (orderNo: string) => {
  return http.request({
    method: 'POST',
    url: '/app/goods/order_sign',
    data: { order_no: orderNo },
  });
};

export const getExpress = (orderNo: string) => {
  return http.request({
    method: 'GET',
    url: '/app/goods/order_express',
    params: { order_no: orderNo },
  });
};

export const traceLogistics = (orderNo: string, expressNo: string, expressCode: string) => {
  return http.request({
    method: 'GET',
    url: '/app/goods/order_logistics',
    params: { order_no: orderNo, express_no: expressNo, express_code: expressCode },
  });
};
